from threading import Thread,Lock
import time
lock = Lock()
totalMoney = 1000
def acount(name,money): # 取钱
    lock.acquire()
    global totalMoney
    if totalMoney>money:  # 如果机子里面的钱多于要取的钱
        time.sleep(1) # 放大问题的发生性
        totalMoney-=money
        print(f"{name}取钱成功")
    else:
        print(f"{name}取钱失败")
    lock.release()
    print(totalMoney)

if __name__ == '__main__':
    t1 = Thread(target=acount,args=("小红",800))
    t2 = Thread(target=acount,args=("小明",800))
    t1.start()
    t2.start()